package com.ash.b.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂核心方法
 */
public class CoffeeFlavorFactory {

    private Map<String, CoffeeFlavor> flavors = new HashMap<>();

    public CoffeeFlavor getCoffeeFlavor(String flavorName) {
        CoffeeFlavor flavor = flavors.get(flavorName);
        if (flavor == null) {
            flavor = new CoffeeFlavor(flavorName);

            flavors.put(flavorName, flavor);
        }

        return flavor;
    }

    public int getTotalCoffeeFlavorsMade() {
        return flavors.size();
    }
}
